package com.itfreer.gather.setting;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.itfreer.gather.R;
import com.itfreer.security.SecurityService;
import com.itfreer.security.UserInfoEntity;
import com.itfreer.security.UserLoginListener;
import com.itfreer.ui.activity.BaseActivity;
import com.itfreer.ui.base.TextView;

/**
 * 系统登录
 */
public class LoginActivity extends BaseActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.setting_login_activity);

        // 返回
        TextView me =(TextView)findViewById(R.id.setting_login_back);
        me.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                finish();
            }
        });

        final EditText userNameText =(EditText)findViewById(R.id.setting_login_username);
        final EditText passwordText =(EditText)findViewById(R.id.setting_login_password);

        //TODO song  设置默认用户名密码
        userNameText.setText("admin");
        passwordText.setText("admin123");

        Button login =(Button)findViewById(R.id.setting_login_btn);
        login.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                final String userName = userNameText.getText().toString();
                final String password = passwordText.getText().toString();

                SecurityService.instance.setUserLoginListener(new UserLoginListener() {
                    @Override
                    public void onSuccess(UserInfoEntity user) {
                        finish();
                    }

                    @Override
                    public void onFail() {
                    }
                });
                SecurityService.instance.login(userName, password, LoginActivity.this);
            }
        });
    }
}
